package Entity;

import java.io.IOException;
import java.io.Serializable;

import Controllers.GlobalData;
/**
 *  InfoSystem represent the info systems for mdata base
 * @author Shimon
 *
 */
public class InfoSystem implements Serializable 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String name;
	private String  description;
	private int infoSystemId;
	private Worker supervisor;
	/**
	 *  Constructors
	 * @param infoSystemId
	 * @param name
	 * @param description
	 * @param supervisor
	 */
	public InfoSystem( int infoSystemId,String name, String description,Worker supervisor) 
	{
		super();
		this.name = name;
		this.description = description;
		this.infoSystemId = infoSystemId;
		this.supervisor = supervisor;
	}
	public InfoSystem(String name, String description,Worker supervisor) 
	{
		super();
		this.name = name;
		this.description = description;
		this.infoSystemId = -1;
		this.supervisor = supervisor;
	}
	public InfoSystem()
	{
	
	}
	
	
	public boolean setNewInfoSystemInDb()
	{
	   Message msg = new Message(3001, GlobalData.MESSAGE_ID(), this);
        
		Message AnswerMessage = null;
		System.out.println("InfoSystem - setNewInfoSystem : Try to Add new info ");
		try 
		{
			GlobalData.client.sendToServer(msg);
			try {
				Thread.sleep(500);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			while (true)
			{
				if (GlobalData.client.isRecivedMessage()==true)
				{
					AnswerMessage = GlobalData.client.getAnsweredMessage(msg);
				    if (AnswerMessage!=null)
				  	      break;
				}	
			}
		} 
		catch (IOException e) 
		{
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("InfoSystem - setNewInfoSystem : Try to Add new info ");
		return  (Boolean) AnswerMessage.getDataGram();
	}
	
	@Override
	/*
	 * (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString()
	{
		if (this.getName()!=null)
		{
			return (this.getName());
		}
		else
		{
			return("No name is assigned");
		}
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public int getInfoSystemId() {
		return infoSystemId;
	}
	public void setInfoSystemId(int infoSystemId) {
		this.infoSystemId = infoSystemId;
	}
	public Worker getSupervisor() {
		return supervisor;
	}
	public void setSupervisor(Worker supervisor) {
		this.supervisor = supervisor;
	}
	
}
